Sample Plug-in
This sample creates a weather app that displays the weather forecast in two ways:
- Display the 7-day weather forecast for the cities in the current itinerary.
- Display the weather forecast for London from the terminal entry #WEATHER <city name>.
To create this plug-in from scratch,
-
Create a new project in Visual Studio. Use a Smartpoint SDK template or create a project from scratch or use the Smartpoint SDK template.
Create a project from scratch- From the File menu, select Create then New Project.
- From Templates > Visual C# > Windows, choose WPF User Control Library. The WPF library is created with all of the references you need.
- Enter a project name and click OK.
-
Go to project properties and ensure you are targeting .NET Framework 4 Client Profile (located in the Application tab under Target framework).
Note: With the release of Travelport Smartpoint 7.5 the target framework changed from .net 4.0 to .net 4.6.2. - Add the Smartpoint assemblies to the project. In the Solution Explorer, right-click on References and click Add Reference.
- Choose Travelport.Smartpoint.dll. The default location for this file is C:\Program Files\Travelport\Smartpoint.
- Add a new class by right-clicking on the project name, then choosing Add > Add a New Class. Name the class. In this sample, the class is named Plugin.cs.
-
Create and set up a plug-in class.
Steps- Within the Plugin.cs file, derive from the host plug-in. Without this step, your plug-in will not work.
-
Define the entry point by overriding the Execute method, which is the main entry point into the plug-in. Do not put any business logic or long-running processes in the Execute method, as it can slow down Smartpoint processes.
Exception: All visual plug-in initiations should occur in Execute. For example, when a plug-in is injecting a button to the UI, add that button in the Execute method to make the addition of the button seamless as Smartpoint loads. If the button is added after Execute, users will see the new button being added after Smartpoint loads.
-
Add the SmartPointPlugin class attribute to define the developer and GUID (globally unique identifier). The GUID is essential if you plan on distributing your plug-in through Marketplace, as it will be used as the license. The GUID displayed on the classifications page is the value that should be used. If you are building a plug-in for use within your agency or do not plan on distributing your plug-in through Marketplace, we recommend creating a GUID through Microsoft Visual Studio (Tools > Create GUID option in the menu) and embedding the GUID in your code now. We will be adding functionality within Marketplace in early 2016 and will be asking you to ‘register’ your plug-in(s) with Marketplace by entering a few pieces of information. Once we turn on our validation, any plug-in that is not recognized by Smartpoint (via the integration with Smartpoint) will not load.
-
Within Execute, subscribe to OnSmartpointReady, which guarantees that certain Smartpoint infrastructure is in place. OnSmartpointReady is where you can add business logic.
-
OnSmartpointReadyHandler defines the events and initializes the weather pop-up. It also subscribes to OnTerminalPresend and OnBookingFileDisplayed events.
- OnTerminalPresend event occurs anytime a user presses the Enter key.
- OnBookingFileDisplayed event occurs when the PNR viewer is refreshed (i.e., new booking file, changed booking file, retrieved booking file, booking file refresh, or end transact).
-
Display weather according to method used.
Display weather associated to current itinerary in PNR viewer.From an OnBookingFileDisplayed event,
-
Within Plugin.cs, the SetWeatherPopup defines how the pop-up within the PNR viewer area displays.
-
A button displays in the PNR contextual toolbar only if a booking file exists and if it has air segments.
-
In the Controls\ToolbarButton.xaml file, the ToolbarButton is defined as SmartPnrContextualToolbarButton, which is a complex object that takes a command and opens a view. The command makes the call to the weather web service. The response is used to populate the view model. The button states are also defined.
-
-
When the OnBookingFileDisplayedHandler is activated, it calls the SetWeatherPopup method.
Display weather from a terminal entry.From an OnTerminalPresend event,
- Each time a user presses Enter in the terminal view, the string entered is compared against the weather entry. If it does not match, the weather app is not called.
If the string matches, call the web service to get forecast data.
Code- The e.TEControl is important, as it specifies that the weather forecast is to be inserted into the terminal window from which the agent requested the weather.
- The e.Handled expression is important. Refer to the note below.
- The e.TerminalEntry expression prevents the #WEATHER entry from being sent to the host.
Important: It is highly recommended that when you create a terminal entry plug-in that you set "e.Handled=false". When "e.Handled=true", it prevents all plug-ins that load after your plug-in from being available.
- The e.TEControl is important, as it specifies that the weather forecast is to be inserted into the terminal window from which the agent requested the weather.
- Update the terminal view with the response.
-
- Activate test harness mode in Smartpoint and attach Visual Studio's debugger to Smartpoint so that you can test your code. Refer to Testing for more information.